package control;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import view.Gui;
import view.GuiList;

public class ExitListener extends WindowAdapter {
	private Gui gui;
	private GuiList guiList;
	
	public ExitListener(Gui gui, GuiList guiList) {
		this.gui = gui;
		this.guiList = guiList;
	}
	
    public void windowClosing(WindowEvent event) {
    	guiList.remove(gui);
        gui.dispose();
        if (guiList.isEmpty()) {
            System.exit(0);
        } else {
            guiList.last().toFront();
        }
    }
}